const app = getApp()

import Dialog from '@vant/weapp/dialog/dialog';
import {
    showMsg
} from '../../../../utils/config.js'

import {
    reqhiddenDangerget,
} from '../../../../request/api.js'

Page({

    data: {
        navHeight: app.globalData.navHeight + 'px', //头部距离
        bottomHeight: app.globalData.bottomHeight + 'px', //iphone底部距离
        fileList:[],
        flag:true,//是否 是工单过来
    },

    onLoad(e) {
        console.log(e);
        this.setData({
            info: JSON.parse(e.info),
            state:e.state
        })
        let info = JSON.parse(e.info)
        // this.gethiddenDangerget(info)
    },
    async onShow() {
        if(this.data.state==1){
            // 工单进来
            this.gethiddenDangerget(this.data.info.hiddenDangerId)
            this.setData({
                flag:false
            })
            return;
        }
        this.gethiddenDangerget(this.data.info.id)
    },
    // 获取隐患信息
    async gethiddenDangerget(id){
        const res = await reqhiddenDangerget(id)
        if (res.code !== 20000) return showMsg(res.message)
        console.log(res);
        let fileList=[]
        if(res.data.row.fileList!=null){
            res.data.row.fileList.forEach(element => {
                fileList.push({
                    url:element.file
                })
            });
        }
        this.setData({
            fileList,
            info:res.data.row
        })
    },
  
    // 去工单详情
    onWork(){
        let info = JSON.stringify(this.data.info)
        console.log(this.data.info);
        wx.navigateTo({
            url: `/packageA/pages/message-index-page/work-details/work-details?info=${info}&state=1`,
        })
    }
  
})